package com.cw.carwashproductcategory.controller;

import com.cw.carwashproductcategory.domain.ProductCategory;
import com.cw.carwashproductcategory.service.ProductCategoryService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/category")
public class ProductCategoryController extends BaseController {

    @Autowired
    private ProductCategoryService productCategoryService;

    /**
     * 查询商品分类列表
     * @param productCategory
     * @return
     */
    @GetMapping("/list")
    public AjaxResult list(ProductCategory productCategory) {
        startPage();
        return success(productCategoryService.selectProductCategoryList(productCategory));
    }

    /**
     * 查询商品分类详情
     * @param id
     * @return
     */
    @GetMapping("/detail/{id}")
    public AjaxResult detail(@PathVariable(value = "id") Long id) {
        return success(productCategoryService.selectProductCategoryById(id));
    }

    /**
     * 新增商品分类
     * @param productCategory
     * @return
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ProductCategory productCategory) {
        return toAjax(productCategoryService.insertProductCategory(productCategory));
    }

    /**
     * 修改商品分类
     * @param productCategory
     * @return
     */
    @PutMapping("/update")
    public AjaxResult update(@RequestBody ProductCategory productCategory) {
        return toAjax(productCategoryService.updateProductCategory(productCategory));
    }

    /**
     * 删除商品分类
     * @param id
     * @return
     */
    @DeleteMapping("/deleteById/{id}")
    public AjaxResult deleteById(@PathVariable Long id) {
        return toAjax(productCategoryService.deleteProductCategoryById(id));
    }

    /**
     * 批量删除商品分类
     * @param ids
     * @return
     */
    @DeleteMapping("/deleteByIds/{ids}")
    public AjaxResult deleteByIds(@PathVariable Long[] ids) {
        return toAjax(productCategoryService.deleteProductCategoryByIds(ids));
    }
}
